<template>
  <div>
    <h2>BeforeRoutePage</h2>


  </div>
</template>

<script>
export default {
  name: "BeforeAuthPage",
  setup() {

  },
  //通过路由规则，进入该组件时被调用
  beforeRouteEnter(to, from, next) {
    console.log('BeforeAuthPage--beforeRouteEnter  过路由规则，进入该组件时被调用')
    if (to.meta.isBeforeAuth) { //判断是否需要鉴权
      if (localStorage.getItem('school') === 'atguigu') {
        next()
      } else {
        localStorage.setItem('school', 'atguigu');
        alert('beforeRouteEnter ture 无权限查看！')
      }
    } else {
      next()
    }
  },
  //通过路由规则，离开该组件时被调用
  beforeRouteLeave(to, from, next) {
    console.log('BeforeAuthPage--beforeRouteLeave')
    localStorage.setItem('school', '');

    next()
  }

}
</script>

<style scoped>
div {
  background: #48b091;
  padding: 10px;
}
</style>